package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmall.user.mapper.AddressMapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AddressService implements IAddressService {
    @Autowired(required = false)
    private AddressMapper addressMapper;

    /**
     * 根据用户id查询用户地址
     *
     * @param id
     * @return
     */
    @Override
    public List<Address> findAddressByUid(Long id) {
        QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        List<Address> addressList = addressMapper.selectList(queryWrapper);
        System.out.println("addressList = " + addressList);
        return addressList;
    }

    /**
     * 根据addressId查询地址
     *
     * @param addressId
     * @return
     */
    @Override
    public Address findAdsByAid(Long addressId) {
        Address address = addressMapper.selectById(addressId);
        System.out.println("根据addressId查询地址__address = " + address);
        return address;
    }
}
